package com.example.demo.domain.system.role;

import com.example.demo.domain.BaseEntity;
import com.example.demo.domain.BaseService;
import com.example.demo.response.CustomRspBody;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SysRoleService extends BaseService<SysRoleEntity> {
    public SysRoleService(){ super(SysRoleEntity.class); }

    public CustomRspBody findAll(Map<String,Object> params){
        Criteria criteria = new Criteria();
        String searchInfo = params.get("searchInfo")+"";
        if(!"".equals(searchInfo)){
            criteria.and("name").regex(searchInfo);
        }
        List<SysRoleEntity> list = this.getList(criteria);
        //无上级代码时，选无
        SysRoleEntity sysRoleEntity = new SysRoleEntity();
        sysRoleEntity.setName("无");
        sysRoleEntity.setCode("空");
        list.add(0, sysRoleEntity);
        return CustomRspBody.success();
    }

}
